package com.ssyt.yt1.day22;

interface Volumeable {

	int getVolume();
}

interface Volume extends Volumeable {
}

interface Voice extends Volumeable {
}

class PersonVoice implements Voice {

	private int volume;

	public PersonVoice() {
		super();
	}

	public PersonVoice(int volume) {
		super();
		this.volume = volume;
	}

	@Override
	public int getVolume() {
		return volume;
	}

	public void setVolume(int volume) {
		this.volume = volume;
	}

}

class DogVoice implements Voice {

	private int volume;

	public DogVoice() {
		super();
	}

	public DogVoice(int volume) {
		super();
		this.volume = volume;
	}

	@Override
	public int getVolume() {
		return volume;
	}

	public void setVolume(int volume) {
		this.volume = volume;
	}

}

class Megaphone implements Volume {

	private Voice voice;
	private int times;

	public Megaphone(Voice voice, int times) {
		this.voice = voice;
		this.times = times;
	}

	@Override
	public int getVolume() {
		return voice.getVolume() * times;
	}
}

/**
 * 装饰模式以对客户端透明的方式扩展对象的功能，是继承关系的一个替代方案（使用组合）。
 * 
 * @author Administrator
 *
 */
public class DecoratorDemo {

	public static void main(String[] args) {
		DogVoice voice = new DogVoice(100);
		System.out.println(voice.getVolume());
		Megaphone megaphone = new Megaphone(voice, 10);
		System.out.println(megaphone.getVolume());
	}
}
